const express = require('express');
const handle = require('../router_handle/news_handle');
const app = express.Router();
const multer = require('multer');
const path = require('path');
const storage = multer.diskStorage({
	destination: function (req, file, cb) {
		cb(null, path.join(__dirname, '../uploads/news'));
	},
	filename: function (req, file, cb) {
		cb(null, 'news' + new Date().valueOf() + path.extname(file.originalname));
	}
})
const upload = multer({
	storage
});

// 添加newsType(post)
// /news/addNewsType
// name create_time
app.post('/addNewsType', handle.addNewsType);
// 修改newsType(post)
// /news/editNewsType
// id name(new)
app.post('/editNewsType', handle.editNewsType);
// 删除newsType(get)
// /news/deleteNewsType
// id
app.get('/deleteNewsType', handle.deleteNewsType);
// 查看newsType(get)
// /news/getNewsType
app.get('/getNewsType', handle.getNewsType);
// 根据id获取newstype(get)
// /news/getNewsTypeById
// id
app.get('/getNewsTypeById', handle.getNewsTypeById);


// 添加news(post)
// /news/addNews
// title content picfile create_time newsTypeId
app.post('/addNews', upload.single('picfile'), handle.addNews)
// 删除news(get)
// /news/deleteNews
// id
app.get('/deleteNews', handle.deleteNews)
// 查看news(get)
// /news/getNews
app.get('/getNews', handle.getNews)
// 根据newstypeid获取news
// /news/getNewsByNewsTypeId
// newstypeid
app.get('/getNewsByNewsTypeId', handle.getNewsByNewsTypeId);
// 通过id获取news
// /news/getNewsById
// id
app.get('/getNewsById', handle.getNewsById);
// 修改news 没有content (post)
// /news/editNewsNoContent
// id title picfile newsTypeId
app.post('/editNewsNoContent', upload.single('picfile'), handle.editNewsNoContent);
// 修改news 有content (post)
// /news/editNewsWithContent
// id content
app.post('/editNewsWithContent', handle.editNewsWithContent);


module.exports = app